package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{

    @Autowired
    private IReservationService reservationService;

    /**
     * 查询当天取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
       int count= reservationService.getCancelledReservationCount(userId);
        return R.ok(count);
    }


    /**
     * 查询每个时间段剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R<List<TimeCountVo>>  countReservationsForEachTimeWithinTimeRange(Long time) {

        List<TimeCountVo> list=reservationService. countReservationsForEachTimeWithinTimeRange(time);
        return R.ok(list);
    }

    /**
     * 新增预约信息
     * @param reservationDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@RequestBody ReservationDto  reservationDto){
       return toAjax( reservationService.insertReservationmsg(reservationDto));
    }

}